package com.yc.util;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.stream.Stream;

public class FileUtil {
    public static void deleteDirectoryStream(Path path) {
        try {
            Files.delete(path);
            System.out.printf("删除文件成功：%s%n",path.toString());
        } catch ( IOException e) {
            System.err.printf("无法删除的路径 %s%n%s", path, e);
        }
    }

    public static void deleteFile(Path path) throws IOException {
        try ( Stream<Path> walk = Files.walk(path)) {
            walk.sorted(Comparator.reverseOrder())
                    .forEach(FileUtil::deleteDirectoryStream);
        }
    }
}
